/*
 * LogFile.h
 *
 *  Created on: Jul 3, 2024
 *      Author: root
 */

#ifndef BSP_LOG_LOGFILE_H_
#define BSP_LOG_LOGFILE_H_
#include <iostream>
#include "basic_header.h"

namespace bsp {

class LogFile {
private:
	FILE *fd;
	std::string filename;
	uint32_t max_size;
	uint32_t rewrite_size;
	bool start;
	char buffer[COMMON_BUFFER_SIZE];

	int copyTail();

public:
	LogFile(const char *file, uint32_t max_size, uint32_t rewrite_tail_size,
			bool start_record) :
			fd { nullptr }, filename { file }, max_size { max_size }, rewrite_size {
					rewrite_tail_size }, start { start_record } {
		ASSERT(file && max_size > 0 && max_size > rewrite_tail_size, "");
	}

	int write(const char *data, uint32_t size);

	virtual ~LogFile();

	static void test1();
};

} /* namespace bsp */

#endif /* BSP_LOG_LOGFILE_H_ */
